﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MVAScratchPad"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModels="using:MVAScratchPad.ViewModels"
    xmlns:common="using:MVAScratchPad.Common"
    xmlns:interop="using:Windows.UI.Xaml.Interop"
    xmlns:Converters="using:MVAScratchPad.Converters"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    x:Class="MVAScratchPad.Views.MainPage"
    x:Name="pageRoot"
    mc:Ignorable="d">
    <Page.Resources>
        <Converters:SubtractConverter x:Key="SubtractConverter"/>
    </Page.Resources>

    <Page.DataContext>
        <viewModels:MainPageViewModel />
    </Page.DataContext>

    <Page.BottomAppBar>
        <CommandBar>

            <AppBarButton Label="Remove" Icon="Remove" IsEnabled="{Binding CanDelete}">
                <AppBarButton.Flyout>
                    <Flyout>
                        <ItemsControl x:Name="itemsControl" ItemsSource="{Binding Notes}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <MenuFlyoutItem Text="{Binding Title}" 
                                        Command="{Binding DataContext.DeleteNoteCommand, ElementName=itemsControl, Mode=OneWay}" 
                                        CommandParameter="{Binding Mode=OneWay}" />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Flyout>
                </AppBarButton.Flyout>
            </AppBarButton>

            <AppBarButton x:Name="AddButton" Label="Add" Icon="Add">
                <AppBarButton.Flyout>
                    <Flyout Placement="Top">
                        <StackPanel x:Name="stackPanel">
                            <TextBox Width="200" Header="New Name" Text="{Binding NewNoteTitle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            <Button Content="Add" Command="{Binding AddNoteCommand, Mode=OneWay}" />
                        </StackPanel>
                    </Flyout>
                </AppBarButton.Flyout>
            </AppBarButton>

        </CommandBar>
    </Page.BottomAppBar>

    <Grid Background="{StaticResource MVAGreen}" x:Name="MyGrid">

        <Hub x:Name="MyHub" Margin="0,0,0,16">
            <Hub.Header>
                <StackPanel Orientation="Horizontal">
                    <Image Height="100" Width="100" Margin="0,-40,40,0" Source="ms-appx:///Assets/Logo.png" Stretch="UniformToFill" />
                    <TextBlock>
						<Run Text="MVA Scratch Pad"/>
                    </TextBlock>
                </StackPanel>
            </Hub.Header>
            <HubSection>
                <DataTemplate>
                    <ItemsControl ItemsSource="{Binding Notes}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid x:Name="itemsWrapGrid" VerticalAlignment="Stretch">
                                    <ItemsWrapGrid.ChildrenTransitions>
                                        <TransitionCollection>
                                            <AddDeleteThemeTransition />
                                        </TransitionCollection>
                                    </ItemsWrapGrid.ChildrenTransitions>
                                </ItemsWrapGrid>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid x:Name="grid" Margin="0,0,80,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <TextBox Grid.Row="0" Text="{Binding Title, Mode=TwoWay}" BorderBrush="Transparent" Background="Transparent" Foreground="White" FontSize="30" Margin="0,0,0,10" IsSpellCheckEnabled="True" />
                                    <TextBox Grid.Row="1" Text="{Binding Notes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="400" TextWrapping="Wrap" FontSize="18" AcceptsReturn="True" IsSpellCheckEnabled="True"
										Height="500" common:TextBoxExtension.SearchBox="{Binding ElementName=SearchBox}"
										MinHeight="{Binding ScreenHeight, ConverterParameter=300, Converter={StaticResource SubtractConverter}, ElementName=pageRoot}" 
										MaxHeight="{Binding ScreenHeight, ConverterParameter=300, Converter={StaticResource SubtractConverter}, ElementName=pageRoot}" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </DataTemplate>
            </HubSection>
        </Hub>

        <SearchBox x:Name="SearchBox" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,40,40,0" Width="250" FocusOnKeyboardInput="False" PlaceholderText="Search" QueryText="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        <common:AppBarHint VerticalAlignment="Bottom" HorizontalAlignment="Stretch" />

    </Grid>

</Page>